package org.az.netty_study.p15_netty参数;

import io.netty.bootstrap.Bootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelOption;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.handler.logging.LoggingHandler;

/**
 * 对于客户端Bootstrap，参数使用option()方法来配置
 */
public class _1_客户端参数 {
    public static void main(String[] args) throws InterruptedException {
        NioEventLoopGroup group = new NioEventLoopGroup();
        Bootstrap client = new Bootstrap()
                .group(group)
                //CONNECT_TIMEOUT_MILLIS表示指定毫秒没有建立连接，则抛出异常
                .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 30)
                .channel(NioSocketChannel.class)
                .handler(new LoggingHandler());
        ChannelFuture future = client.connect("127.0.0.1", 8080);
        future.sync().channel().closeFuture().sync();

        group.shutdownGracefully();
    }
}
